package com.lvyq.util;

import com.lvyq.model.user.User;
import lombok.extern.java.Log;
import org.junit.Test;

import java.util.List;

/**
 * @program: weg
 * @description:
 * @author: lvyq
 * @create: 2023-03-21 20:16
 **/
@Log
public class JueWeiCheckUtils {





    @Test
    public void   demo1(){
        Integer[] jingyans={0,10,20,30,40,50,60,70,80,90,100};
        Integer uJingyan = 5;
        for (int i=0;i<jingyans.length;i++){
            if (uJingyan>=jingyans[i] && uJingyan<jingyans[i+1] ){
                log.info("mid="+i);
            }
        }
    }

    @Test
    public void   demo2(){
        Integer[] jingyans={0,10,20,30,40,50,60,70,80,90,100};
        Integer uJingyan = 10;
        int left=0;
        int right=jingyans.length-1;
        int resut=0;
        while (left<=right){
            int mid = (left+right)/2;
            if (uJingyan<jingyans[mid]){
                right=mid;
                if (right==resut){
                    break;
                }
                resut=right;
                log.info("mid>>"+resut);
            }
            if (uJingyan>jingyans[mid]){
                left=mid;
                if (left==resut){
                    break;
                }
                resut=left;
                log.info("leftmid>>"+(resut-1));
            }
            if(uJingyan==jingyans[mid]){
                resut=mid;
                log.info("ismid>>"+mid);
                break;
            }

        }
        log.info("resule>>>"+resut);
    }
}
